//
//  ProjectPeopleInfoViewController.m
//  mhome
//
//  Created by YaSha_Tom on 2018/12/7.
//  Copyright © 2018年 刘春雷. All rights reserved.
//

#import "ProjectPeopleInfoViewController.h"
#import "YSPMSInfoHeaderView.h"
#import "ProjectPeopleModel.h"
#import "YSPMSPeopleInfoCell.h"
#import "YSNetManager.h"
#import "DataManager.h"

@interface ProjectPeopleInfoViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,copy) NSArray *dataSourceArray;
@property(nonatomic, strong) YSPMSInfoHeaderView *infoHeaderView;
@end

@implementation ProjectPeopleInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"人员信息";
    [self initUI];
    [self doNetworking];
}
- (void)initUI {
    self.tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}
- (void)doNetworking {
    [YSNetManager ys_request_GETWithUrlString:[NSString stringWithFormat:@"%@%@/%@/0", YSDomain, getPersonsListApp, self.projectId] isNeedCache:NO parameters:nil successBlock:^(id response) {
        NSLog(@"-------%@",response);
        self.dataSourceArray = [DataManager getPMSPeopleData:response];
        [self.tableView reloadData];;
    } failureBlock:^(NSError *error) {
        NSLog(@"=======%@",error);
    } progress:nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 52*kHeightScale;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, kSCREEN_WIDTH, 42*kHeightScale)];
    backView.backgroundColor = [UIColor whiteColor];
    
    self.infoHeaderView = [[YSPMSInfoHeaderView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [backView addSubview:self.infoHeaderView];
    ProjectPeopleModel *model = self.dataSourceArray[section];
    self.infoHeaderView.positionLabel.text = model.typeStr;
    return backView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YSPMSPeopleInfoCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell) {
        cell = [[YSPMSPeopleInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"peopleInfoCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    ProjectPeopleModel *model = self.dataSourceArray[indexPath.section];
    [cell setPeopleInfoCell:model];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
